package feeinterface.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.ulwx.database.DbException;
import com.ulwx.tool.DbUtils;
import feeinterface.modeldb.BaseSmsModemPort;

public class BaseSmsModemPortDao {

	public BaseSmsModemPortDao() {
		// 构造函数
	}

	/**
	 * 取得短信猫的手机号码
	 * 
	 * @return
	 * @throws DbException
	 */
	public static BaseSmsModemPort getSmsPort() throws Exception {
		BaseSmsModemPort smsPort = null;
		String sql = " SELECT * FROM BaseSmsModemPort WHERE ENABLE = 1 ORDER BY RAND() LIMIT 1 ";

		Map<Integer, Object> args = new HashMap<Integer, Object>();
		List<BaseSmsModemPort> list = DbUtils.doQueryClass(null,
				BaseSmsModemPort.class, sql, args);
		if (list != null && list.size() > 0) {
			smsPort = list.get(0);
			// 如果有找到，就更新该手机号码的使用次数
			sql = "UPDATE BaseSmsModemPort SET UseCnt = UseCnt + 1 WHERE BsSmsModemPortSno = ?";
			args.clear();
			args.put(1, smsPort.getBsSmsModemPortSno());
			DbUtils.executeBindUpdate(null, sql, args);
		}
		return smsPort;
	}

}
